#include <stdio.h>

void merge_2list(int arr[], int temp[], int l1, int r1, int l2, int r2)
{
	int i = l1, j = l2, k = l1;
	while (i <= r1 && j <= r2) 
		temp[k++] = arr[i] < arr[j] ? arr[i++]:arr[j++];

	while (i <= r1) temp[k++] = arr[i++];
	while (j <= r2) temp[k++] = arr[j++];
	
	for (k = l1; k <= r2; k++)
		arr[k] = temp[k];
}

void merge_sort_recursive(int arr[], int temp[], int l, int r)
{
	int mid;
	if (l == r) return ;
	
	mid = (l+r)/2;
	merge_sort_recursive(arr,temp,l,mid);
	merge_sort_recursive(arr,temp,mid+1,r);
	merge_2list(arr,temp, l,mid, mid+1,r);
}

void merge_sort(int arr[], int n)
{
	int temp[n];
	merge_sort_recursive(arr,temp,0,n-1);	
}
	
void main()
{
	int i,a[]={13,50,27,-1,70,10,33,82,100,29,5,14,33,50};
	int len = sizeof(a)/sizeof(a[0]);
	merge_sort(a,len);
	for(i=0; i<len; i++)
		printf("%d ", a[i]);
}